using huqiang.Core.HGUI;
using System;
using UnityEngine;
using huqiang.UIComposite;
using huqiang.UIEvent;
using huqiang;
using huqiang.Data;
using huqiang.UIModel;
using System.Collections.Generic;

public class StartPage:UIPage
{
    //反射UI界面上的物体
    class View
    {
        public ScrollY scrollY;
    }
    class Item
    {
        public UserEvent BG;
        public HImage Image;
        public HText Text;
        public string str;
    }
    View view;
    public override void Initial(UIElement parent, object dat = null)
    {
        base.Initial(parent, dat);
        view = LoadUI<View>("baseUI", "StartPage");//"baseUI"创建的bytes文件名,"page"为创建的页面名
        InitialData();
    }
    void InitialData()
    {
        List<string> dat = new List<string>();
        for(int i=0;i<400;i++)
        {
            dat.Add(i.ToString());
        }
        view.scrollY.SetItemUpdate<Item, string>(ItemUpdate);
        view.scrollY.BindingData = dat;
        view.scrollY.Refresh();
    }
    void ItemUpdate(Item item,string str,int index)
    {
        item.BG.DataContext = item;
        item.Text.Text = str;
        item.str = str;
        item.BG.Click = (o, e) => { 
            Debug.Log((o.DataContext as Item).str); 
        };
    }
}
